<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>

    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <script src="js/common.js"></script>
</head>
<body>
<div id="myDiv">

</div>
<script type="text/javascript">
    new Vue({
        el:"#myDiv",
        mounted(){
            //解析参数对象
            let url = location.href;// http://bugtracker.itsource.cn/callback.html?code=061YjR000bnz2O1bS4400Tl4bP0YjR0A&state=1
            let paramObj = parseUrlParams2Obj(url);

            let params = {"code":paramObj.code};

            //发起微信登录请求
            this.$http.post("/login/wechat",params)
                .then(result=>{
                    result = result.data;
                    if(result.success){
                        //做登录
                        //提示
                        let {token,logininfo} = result.resultObj;
                        //保存数据到本地
                        localStorage.setItem("token",token);
                        localStorage.setItem("logininfo",JSON.stringify(logininfo));
                        //跳转到主页
                        location.href = "index.html";
                    }else{ //没有关联跳转关联页面
                        ////获取发送请求参数，拼接后端的拼接参数
                        let binderUrl = "http://bugtracker.itsource.cn/binder.html" + result.resultObj;
                        //跳转到绑定页面
                        location.href = binderUrl;

                    }
                })
                .catch(result=>{
                    alert("系统错误");
                    console.log(result);
                })
        }
    });
</script>
</body>
</html>